import $ from "jquery";
import {message} from 'antd'
import {url} from "../../util/config";
import login from "../login";
function getNewLogin(item) {
    return insertNotice(item);
}
export default function insertNotice(item) {
    console.log("item",item);
    let token = localStorage.getItem("token")
    let status;
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+`Notice/InsertNotice`,
        type: 'POST',
        contentType:"application/json",
        data: JSON.stringify({
                NAME:item.name ,		//公告名称
                CONTENT:item.content, 	//公告内容
                ARTICLE_NEW:item.new,   //提醒時間
                DESC:item.desc,		    //公告描述
                TOP_STATUS:item.status,	//是否置顶，不传值默认否
                ATTACH_URL:item.attachUrls, 		//附件的url数组
                ATTACH_NAME:item.attachNames,	//附件的原名称数组
                ATTACH_NUM:item.attachNum 		//附件数
            }
        ),
        success: function (result) {
            status = result.result
            if(status=="Token過期請重新登錄"){
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(item)
            }else {
                if(status=="ok"){
                    message.success("新增成功")
                }else {
                    message.error("新增失败")
                }
            }
        },
        error:function (error) {
            status = "error"
            message.error("请求异常")
        }
    })
    return status;
    // return 'ok'
}
